<?php

/**
 * @author      :   QuangLT
 * @name        :   Plun_Plugin_Auth
 * @version     :   1.0
 * @copyright   :   Plun-Asia
 */

class Plun_Db
{

    /**
     * Hold Zend_Config_Ini instances
     * @var Array
     */
    protected static $_instances = array();

    /**
     * Avoid creation of class instance
     */
    protected function __construct()
    {
    }

    protected function __clone()
    {
    }

    /**
     * Get database
     * @param <string> $instance
     * @return <Zend_Db>
     */
    public static function getInstance($instance)
    {
        if (!$instance) {
            throw new Zend_Db_Exception('No database instance was defined.');
        }

        if (!isset(self::$_instances[$instance])) {
            $config = Plun_Config::get('database')->$instance;

            self::$_instances[$instance] = Zend_Db::factory($config->adapter, $config->params);
        }

        return self::$_instances[$instance];
    }

}